package yr.website

import grails.transaction.Transactional

@Transactional
class MenuService {
    protected Map ser(String permssionId) {
        def menu = Menu.findByPermissionId(permssionId)
        def map = [name: menu.name, url: menu.url, id: menu.id, icon: menu.icon]
        if (menu.pid) {
            //解析pid数组
            def m = []
            def pids = menu.pid.split(",")
            pids.each { pid ->
                m.add(ser(pid))
            }
            map.put("children", m)
        }
        return map
    }

    protected Map ss(Menu menu) {
        def map = [label: menu.name]
        if (menu.pid) {
            def m = []
            def pids = menu.pid.split(",")
            pids.each { pid ->
                def me = Menu.findByPermissionId(pid)
                m.add(ss(me))
            }
            map.put("children", m)
        } else {
            def list = []
            def m = [label: menu.name]
            list.add(m)
            map.put("children", list)
        }
        return map
    }
}
